package com.wanxi.controller;

import com.wanxi.VO.NewsVO;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * 新闻
 * @Author : 林子淳
 * @create 2023/3/10 16:32
 */
@RestController
public class NewsController {
    @Autowired
    private NewsService newsService;

    @PostMapping("/back/news/add")
    @CrossOrigin
    protected ResultDTO Add(NewsVO newsVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = newsService.add(newsVO);
        return resultDTO;
    }
    @PostMapping("/back/news/delete")
    @CrossOrigin
    protected ResultDTO delete(NewsVO newsVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = newsService.delete(newsVO);
        return resultDTO;
    }
    @GetMapping("/back/news/findAll")
    @CrossOrigin
    protected ResultDTO findAll(NewsVO newsVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = newsService.findAll(newsVO);
        return resultDTO;
    }
    @GetMapping("/back/news/findById")
    @CrossOrigin
    protected ResultDTO findById(NewsVO newsVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = newsService.findById(newsVO);
        return resultDTO;
    }
    @PostMapping("/back/news/update")
    @CrossOrigin
    protected ResultDTO update(NewsVO newsVO,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultDTO resultDTO = newsService.update(newsVO);
        return resultDTO;
    }
}
